package com.lxw.manager.cms.service;

import com.lxw.api.cms.CmsConfigControllerApi;
import com.lxw.framework.domain.cms.CmsConfig;
import com.lxw.framework.domain.cms.response.CmsCode;
import com.lxw.framework.exception.ExceptionCast;
import com.lxw.framework.model.response.CommonCode;
import com.lxw.manager.cms.dao.CmsConfigRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class CmsConfigService implements CmsConfigControllerApi {

    @Autowired
    private CmsConfigRepository cmsConfigRepository;

    @Override
    public CmsConfig findCmsConfigById(String id) {
        if (StringUtils.isEmpty(id)){
            ExceptionCast.cast(CommonCode.INIT_PARAM);
        }
        Optional<CmsConfig> optional = cmsConfigRepository.findById(id);

        if (optional.isPresent()){
            System.out.println(optional.get());
            return  optional.get();
        }
        return null;
    }


}
